package jaux.tank.bean.entity.system;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;

import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;

import jaux.tank.bean.core.ShiroUser;
import jaux.tank.shiro.ShiroKit;
import lombok.Getter;
import lombok.Setter;

@MappedSuperclass
@Getter
@Setter
public class EntityWithSoftDelete extends EntityWithAudit {

	@PreRemove
	private void preRemove() {
		preUpdate();
		deleted = true;
		deleteTime = DateTimeFormatter.ofPattern(DATETIME_FORMAT).format(LocalDateTime.now());
		Optional<ShiroUser> user = ShiroKit.getUser();
		if(user.isPresent()) {
			deletedBy = user.get().getId();
		}
	}
	private boolean deleted; 
	
    private String deleteTime;
    
    private String deletedBy;
    
}
